package com.acwing.lc.part1;

/**
 * @author rkc
 * @date 2022/9/9 10:54
 */
public class LC14最长公共前缀 {

    public String longestCommonPrefix(String[] strs) {
        StringBuilder sb = new StringBuilder();
        int min = 210;
        for (String str : strs) min = Math.min(min, str.length());
        for (int i = 0; i < min; i++) {
            boolean flag = true;
            for (int j = 1; j < strs.length; j++) {
                if (strs[j].charAt(i) != strs[0].charAt(i)) {
                    flag = false;
                    break;
                }
            }
            if (flag) sb.append(strs[0].charAt(i));
            else break;
        }
        return sb.toString();
    }
}
